﻿@using Blog.MVP.Blazor.Models

@inherits LayoutComponentBase


<div>
    <div class="form-group">
        <label>标题</label>
        <input @bind="BlogArticle.btitle" class="form-control" />
    </div>
    <div class="form-group">
        <label>分类</label>
        <input @bind="BlogArticle.bcategory" class="form-control" />
    </div>
    <div class="form-group">
        <label>作者</label>
        <input @bind="BlogArticle.bsubmitter" class="form-control" />
    </div>
    <div class="form-group">
        <label>内容</label>
        <input @bind="BlogArticle.bcontent" class="form-control" />
    </div>

    <button class="btn btn-primary" @onclick="TrySave">
        保存
    </button>

    <CancelBtn Name="取消"></CancelBtn>
</div>

@code{

    [Parameter]
    public BlogArticle BlogArticle { get; set; }
    [Parameter]
    public EventCallback<BlogArticle> OnSaveCallback { get; set; }

    protected override Task OnInitializedAsync()
    {
        if (BlogArticle == null)
        {
            BlogArticle = new BlogArticle();
            BlogArticle.bcategory = "技术博文";
        }

        return Task.CompletedTask;
    }

    private void TrySave()
    {
        OnSaveCallback.InvokeAsync(BlogArticle);
    }
}